package org.zoomdev.zoom.dao;

import org.zoomdev.zoom.common.expression.Symbol;

import java.util.Collection;
import java.util.List;
import java.util.Map;

public interface SqlBuilder extends Sql<SqlBuilder> {


    String COUNT = "COUNT(*)";

    /**
     * 等于
     *
     * @param key
     * @param value
     * @return
     */
    SqlBuilder where(String key, Object value);

    /**
     * @param key
     * @param like
     * @param value
     * @return
     */
    SqlBuilder like(String key, Like like, Object value);

    SqlBuilder orLike(String key, Like like, Object value);

    /**
     * @param key
     * @param symbol > < >= <= <> =
     * @param value
     * @return
     */
    SqlBuilder where(String key, Symbol symbol, Object value);

    /**
     * where {name} is null
     *
     * @param key
     * @return
     */
    SqlBuilder whereNull(String key);

    /**
     * where {name} in (  ?,?,?  ), 1,2,3
     *
     * @param key
     * @param values
     * @return
     */
    <T> SqlBuilder whereIn(String key, Collection<T> values);

    /**
     * 相当于 where    (    condition     )
     *
     * @param where
     * @return
     */
    SqlBuilder where(Condition where);

    /**
     * having('selectSum(user)',Symbo.gt,50)
     *
     * @return
     */
    SqlBuilder having(String key, Symbol symbol, Object value);

    SqlBuilder orWhere(String key, Object value);

    SqlBuilder orWhere(String key, Symbol symbol, Object value);

    /**
     * whereCondition ("a=? and b=? and c=?", 1 , 2, 3)
     * 注意这里不要写成  a=1 and b=2 and c=3,
     *
     * @param value
     * @return
     */
    SqlBuilder whereCondition(String value, Object... values);

    /**
     * or where ...
     *
     * @param condition
     * @return
     */
    SqlBuilder orWhere(Condition condition);

    SqlBuilder whereNotNull(String key);


    /**
     * where {name} not in ( 1, 2, 3 )
     *
     * @param key
     * @param values
     * @return
     */
    <E> SqlBuilder whereNotIn(String key, Collection<E> values);

    /**
     * @param key
     * @param like
     * @param value
     * @return
     */
    SqlBuilder notLike(String key, Like like, Object value);

    /**
     * .innerJoin("table_a","table_a.id=table_b.id",)
     *
     * @param table
     * @param on
     * @return
     */
    SqlBuilder join(String table, String on);


    SqlBuilder join(String table, String on, JoinType type);

    SqlBuilder union(SqlBuilder builder);

    SqlBuilder unionAll(SqlBuilder builder);

    /**
     * 按照排序
     *
     * @param field
     * @param sort
     * @return
     */
    SqlBuilder orderBy(String field, Sort sort);

    SqlBuilder groupBy(String field);

    /**
     * select("selectSum(count) as count,selectMin(id),a ,b ","c","d")
     *
     * @param fields
     * @return
     */
    SqlBuilder select(String fields);

    SqlBuilder selectSum(String field, String alias);

    SqlBuilder selectMax(String field, String alias);

    SqlBuilder selectMin(String field, String alias);

    SqlBuilder selectCount(String alias);

    SqlBuilder selectAvg(String field, String alias);

    SqlBuilder set(String key, Object value);

    SqlBuilder setAll(Map<String, Object> data);

    SqlBuilder clear();

    //void buildSelect();

    List<Object> values();


    String sql();

    String printSql();

}
